#define BOOST_TEST_MODULE TestEnv
#include <boost/test/included/unit_test.hpp>
#include <map>

#include "wrapper.hpp"

#define STR(x) #x

std::string GetPlatfomrInfo(cl_platform_id&  platform,
                            cl_platform_info param_name)
{
    size_t param_value_size = 0;

    clGetPlatformInfo(platform, param_name, 0, nullptr, &param_value_size);
    char* param_value = new char[param_value_size];
    clGetPlatformInfo(platform,
                      param_name,
                      param_value_size,
                      param_value,
                      nullptr);

    std::string param_value_str(param_value);
    delete[] param_value;

    return param_value_str;
}

BOOST_AUTO_TEST_CASE(QueryPlatformInfo)
{
    CLWrapper cl;

    if (cl.Init())
    {
        auto platform = cl.GetPlatformID();

        BOOST_CHECK(platform != nullptr);

        // 获取平台信息
        std::map<cl_platform_info, std::string> param_names = {
            {CL_PLATFORM_NAME,       STR(CL_PLATFORM_NAME)      },
            {CL_PLATFORM_PROFILE,    STR(CL_PLATFORM_PROFILE)   },
            {CL_PLATFORM_VERSION,    STR(CL_PLATFORM_VERSION)   },
            {CL_PLATFORM_VENDOR,     STR(CL_PLATFORM_VENDOR)    },
            {CL_PLATFORM_EXTENSIONS, STR(CL_PLATFORM_EXTENSIONS)}
        };

        for (auto param_name : param_names)
        {
            std::string param_value =
                GetPlatfomrInfo(platform, param_name.first);

            std::cout << param_name.second << ":\t" << param_value.data()
                      << '\n';
        }
    }
}